package actions;

import net.sf.json.JSONObject;
import utils.JSONResponse;
import utils.Pub;

import com.opensymphony.xwork2.ActionSupport;

public class CMActionSupport extends ActionSupport {
	private boolean filedError = true;

	@Override
	public boolean hasFieldErrors() {
		return this.filedError;
	}

	@Override
	public void addFieldError(String fieldName, String errorMessage) {
		this.filedError = true;
		JSONObject json = new JSONObject();
		json.put(Pub.STATUS, false);
		json.put(Pub.MESSAGE, errorMessage);
		json.put("para", fieldName);
		JSONResponse.returnJsonToResponse(json);
	}

	@Override
	public void validate() {
		this.filedError = false;
	}

	protected String convertBorrowTime(int timeNumber) {
		String borrowTime;
		switch (timeNumber) {
			case 1:
				borrowTime = "上午";
				break;
			case 2:
				borrowTime = "下午";
				break;
			case 3:
				borrowTime = "晚上";
				break;
			default:
				borrowTime = "未获取到借用时间";
		}
		return borrowTime;
	}
}
